package com.example.demo.controller;

import com.example.demo.model.User;
import com.example.demo.tool.ResponseMessage;
import com.example.demo.service.UserService;
import com.example.demo.tool.Result;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.security.sasl.SaslServer;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 编写者：施皓
 * 编写时间：2019.5.27
 */
@RestController(value = "/User")
public class UserController {
    @Autowired
    private UserService UserService;

    @ApiOperation(value = "用户登录")
    @CrossOrigin
    @RequestMapping(value = "/getlogin", method = RequestMethod.PUT)
    public String setUserStr(@RequestBody User user){
        String returnStr="";
        if (user!=null){
            if(!user.getName().isEmpty() && !user.getPassword().isEmpty()){

                returnStr=UserService.getUser(user);
            }
        }
        return returnStr;
    }


    @RequestMapping(value = "/getUserStr")
    public String getStr(String str){
        return "你输入的名字叫" + str;

    }
    @CrossOrigin
    @RequestMapping(value = "/getUserOne")
    public User getOne(Integer uid){
        return UserService.selectByPrimaryKey(uid);
    }
//shi
@CrossOrigin
@RequestMapping(value = "getshi")

public List<User> shiKey(String selrisbegin){

    List<User> listRole = UserService.shiKey(selrisbegin);
    return listRole;
}

//
@CrossOrigin//解决跨越问题
@RequestMapping(value = "getrpart",method = RequestMethod.PUT)
public List<User> getrpart(){
    System.out.println("调用角色全部类型的接口");
    List<User> listRole = UserService.getrpart();
    return listRole;
}
//sex
@CrossOrigin//解决跨越问题
@RequestMapping(value = "getdsex",method = RequestMethod.PUT)
public List<User> getdsex(){
    System.out.println("调用角色全部类型的接口");
    List<User> listRole = UserService.getdsex();
    return listRole;
}
    //jur
    @CrossOrigin//解决跨越问题
    @RequestMapping(value = "getdjur",method = RequestMethod.PUT)
    public List<User> getdjur(){
        System.out.println("调用角色全部类型的接口");
        List<User> listRole = UserService.getdjur();
        return listRole;
    }
    //office
    @CrossOrigin//解决跨越问题
    @RequestMapping(value = "getdoffice",method = RequestMethod.PUT)
    public List<User> getdoffice(){
        System.out.println("调用角色全部类型的接口");
        List<User> listRole = UserService.getdoffice();
        return listRole;
    }
    //org
    @CrossOrigin//解决跨越问题
    @RequestMapping(value = "getiorg",method = RequestMethod.PUT)
    public List<User> getiorg(){
        System.out.println("调用角色全部类型的接口");
        List<User> listRole = UserService.getiorg();
        return listRole;
    }
//uid
@CrossOrigin
@RequestMapping(value = "getuid")

public List<User> uidKey(int uid){

    List<User> listRole = UserService.selectByPrimaryKey(uid);
    return listRole;
}
    @CrossOrigin//解决跨越问题
    @RequestMapping(value = "getUserIsBegin",method = RequestMethod.PUT)
    public List<User> getIsBegin(){
        System.out.println("调用角色全部类型的接口");
        List<User> listRole = UserService.getIsBegin();
        return listRole;
    }

    @CrossOrigin
    @RequestMapping(value = "getUserAll")
    public ResponseMessage getAll(){
        List<User> listUser = UserService.getAll();
        System.out.println("调用角色全部信息的方法");
        Map<String,List> map = new HashMap<>();
        map.put("list",UserService.getAll());
        return Result.success("200",map);
    }
    @CrossOrigin
    @RequestMapping(value = "/delUserRole",method =  RequestMethod.GET)
    public int delRole(Integer uid){
        return UserService.delRole(uid);
    }

    @CrossOrigin
    @RequestMapping(value = "/addUserRole",method = RequestMethod.PUT)
    public int addRole(@RequestBody User usermodel){
        //判断传入数据是否为空
        if (usermodel!=null){

        }else {

        }
        return UserService.insertRole(usermodel);
    }
    @CrossOrigin
    @RequestMapping(value = "/updateUser",method = RequestMethod.PUT)
    public  int updateRole(@RequestBody User usermodel){
        if (usermodel!=null){

        }else {

            System.out.println("请输入数据");
        }
        return UserService.updateRole(usermodel);
    }
}
